/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.ucase.casemain.controller;

import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.punish.api.vo.CasePartyRecordAdjustSaveReturnDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICaseInfoAdjustRecordService;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CaseInfoAdjustRecordVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 描述：案件信息调整记录前端控制器
 *
 * @author xiangyuyu
 * @date 2022-06-16 19:13
 */

@RestController
@RefreshScope
@RequestMapping("/punish/ucase/case/main/adjust/record")
@Slf4j
public class CaseInfoAdjustRecordController extends BaseController {
    @Resource
    private ICaseInfoAdjustRecordService caseInfoAdjustRecordService;

    /**
     * 【V1.3.0】描述：获取案件信息调整分页记录
     *
     * @param request {@link CaseInfoAdjustRecordPageRequest} 分页请求对象
     * @return Result<PageResponse < CaseInfoAdjustRecordVo>> 案件信息调整分页记录
     * @author xiangyuyu
     * @date 2022-06-16 19:48
     */
    @PostMapping("/getCaseInfoAdjustPageList")
    @ApiOperation(value = "【V1.3.0】描述：获取案件信息调整分页记录", httpMethod = "POST")
    public Result<PageResponse<CaseInfoAdjustRecordVo>> getCaseInfoAdjustPageList(@RequestBody @Validated CaseInfoAdjustRecordPageRequest request) {
        List<CaseInfoAdjustRecordVo> pageList = caseInfoAdjustRecordService.getCaseInfoAdjustPageList(request);
        return Result.success(new PageResponse<>(pageList));
    }

    /**
     * 【V1.3.0】描述：保存案件信息调整记录
     *
     * @param saveDto {@link CaseInfoAdjustRecordDto}
     * @return Result<String> 保存结果
     * @author xiangyuyu
     * @date 2022-06-16 19:48
     */
    @PostMapping("/saveCaseInfoAdjustRecord")
    @ApiOperation(value = "【V1.3.0】描述：保存案件信息调整记录", httpMethod = "POST")
    public Result<String> saveCaseInfoAdjustRecord(@RequestBody @Validated CaseInfoAdjustRecordDto saveDto) {
        int count = caseInfoAdjustRecordService.saveCaseInfoAdjustRecord(saveDto);
        return Result.success((count == Constant.INTEGER_1) ? Constant.STRING_SAVE_SUCCESS : Constant.STRING_SAVE_FAIL);
    }

    /**
     * 【V1.3.0】描述：查询案件信息调整记录
     *
     * @param request {@link CaseInfoAdjustRecordRequest}
     * @return Result<List < CaseInfoAdjustRecordVo>> 案件信息调整记录
     * @author xiangyuyu
     * @date 2022-06-16 19:48
     */
    @PostMapping("/getCaseInfoAdjustRecordList")
    @ApiOperation(value = "【V1.3.0】描述：查询案件信息调整记录", httpMethod = "POST")
    public Result<List<CaseInfoAdjustRecordVo>> getCaseInfoAdjustRecordList(@RequestBody @Validated CaseInfoAdjustRecordRequest request) {
        List<CaseInfoAdjustRecordVo> list = caseInfoAdjustRecordService.getCaseInfoAdjustRecordList(request);
        if (ObjectUtils.isEmpty(list) || list.size() == 0) {
            return Result.error("暂无调整记录");
        }
        return Result.success(list);
    }

    /**
     * 【V1.3.0】描述：保存当事人调整信息
     *
     * @param saveDto {@link CasePartyInfoAdjustDto}
     * @return Result<String> 保存结果
     * @author xiangyuyu
     * @date 2022-06-16 19:48
     */
    @PostMapping("/saveAdjustInfoWithParty")
    @ApiOperation(value = "【V1.3.0】描述：保存当事人调整信息", httpMethod = "POST")
    public Result<String> saveAdjustInfoWithParty(@RequestBody @Validated CasePartyInfoAdjustDto saveDto) {
        int count = caseInfoAdjustRecordService.saveAdjustInfoWithParty(saveDto);
        return (count == Constant.INTEGER_1) ?
                Result.success(Constant.STRING_SAVE_SUCCESS) : Result.error(Constant.STRING_SAVE_FAIL);
    }

    @PostMapping("/saveAdjustInfoWithHandlePerson")
    public Result<String> saveAdjustInfoWithHandlePerson(@RequestBody @Validated CasePartyInfoAdjustDto saveDto) {
        int count = caseInfoAdjustRecordService.saveAdjustInfoWithParty(saveDto);
        return (count == Constant.INTEGER_1) ?
                Result.success(Constant.STRING_SAVE_SUCCESS) : Result.error(Constant.STRING_SAVE_FAIL);
    }

    /**
     * 【V1.11.2】描述：调整当事人接口
     *
     * @param saveDto 保存dto
     * @return {@link Result<CasePartyRecordAdjustSaveReturnDto> }
     * @author shishengyao
     * @date 2023/03/20
     */
    @PostMapping("/adjustPartyRecord")
    @ApiOperation(value = "【V1.0.0】描述：调整当事人接口", httpMethod = "POST")
    public Result<CasePartyRecordAdjustSaveReturnDto> adjustPartyRecord(@RequestBody @Validated CasePartyRecordAdjustSaveDto saveDto){
        return Result.success(caseInfoAdjustRecordService.saveAdjustPartyRecord(saveDto));
    }

    /**
     * 【V1.11.2】描述：获取调整当事人详情接口
     *
     * @param queryDto 查询dto
     * @return {@link Result<CasePartyRecordAdjustSaveDto> }
     * @author shishengyao
     * @date 2023/03/24
     */
    @PostMapping("/getAdjustPartyRecordDetail")
    @ApiOperation(value = "【V1.0.0】描述：获取调整当事人详情接口", httpMethod = "POST")
    public Result<CasePartyRecordAdjustSaveDto> getAdjustPartyRecordDetail(@RequestBody @Validated AdjustPartyRecordDetailQueryDto queryDto){
        return Result.success(caseInfoAdjustRecordService.getAdjustPartyRecordDetail(queryDto));
    }

    /**
     * 【V1.11.2】描述：校验是否不存在未完成的调整当事人接口记录
     *
     * @param caseId 用例id
     * @return {@link Result<Boolean> }
     * @author shishengyao
     * @date 2023/03/24
     */
    @GetMapping("/isExistUndoneAdjustPartyRecord")
    @ApiOperation(value = "【V1.11.2】描述：是否存在未完成的调整当事人接口记录", httpMethod = "GET")
    public Result<Boolean> isExistUndoneAdjustPartyRecord(@RequestParam("caseId") String caseId){
        return Result.success(caseInfoAdjustRecordService.isExistUndoneAdjustPartyRecord(caseId));
    }
}
